package com.teama4.shop.service;

import com.teama4.shop.domain.Specification;
import com.teama4.shop.domain.SpecificationExample;
import com.teama4.shop.mapper.SpecificationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpecificationServiceImpl implements SpecificationService {
    @Autowired
    private SpecificationMapper specificationMapper;
    @Override
    public long countByExample(SpecificationExample example) {
        return specificationMapper.countByExample(example);
    }

    @Override
    public int deleteByExample(SpecificationExample example) {
        return specificationMapper.deleteByExample(example);
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return specificationMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Specification record) {
        return specificationMapper.insert(record);
    }

    @Override
    public int insertSelective(Specification record) {
        return specificationMapper.insertSelective(record);
    }

    @Override
    public List<Specification> selectByCommodity(int id) {
        return specificationMapper.selectByCommodity(id);
    }

    @Override
    public Specification selectByPrimaryKey(Integer id) {
        return specificationMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByExampleSelective(Specification record, SpecificationExample example) {
        return specificationMapper.updateByExampleSelective(record,example);
    }

    @Override
    public int updateByExample(Specification record, SpecificationExample example) {
        return specificationMapper.updateByExample(record,example);
    }

    @Override
    public int updateByPrimaryKeySelective(Specification record) {
        return specificationMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Specification record) {
        return specificationMapper.updateByPrimaryKey(record);
    }

    @Override
    public int save(Specification specification) {
        if(specification.getId() == null) {
            return specificationMapper.insert(specification);
        } else {
            return specificationMapper.updateByPrimaryKey(specification);
        }
    }

    @Override
    public int selectMerchantIdBySpecificationCommodityId(Integer commodityId) { return specificationMapper.selectMerchantIdBySpecificationCommodityId(commodityId); }
}
